<html>
    <head>
        <script type="text/javascript">
            function append(){
                var oScript = document.createElement("script"); 
                oScript.type = "text/javascript"; 
                oScript.id = "test"; 
                oScript.defer = true; 
                oScript.text = "aa=function() {alert(1);}"; 
                document.getElementsByTagName("head")[0].appendChild(oScript); 
            }
            
            function remove(){
                try {
                    document.getElementsByTagName("head")[0].removeChild(document.getElementById("test"));
                }catch(e){
                    alert(e);
                };
                try {
                    delete aa;
                }catch(e){
                    alert(e);
                };
            }
        </script> 
    </head>
    <body>
        <button id="append" onClick="javascript:append();">加载</button>
        <button id="remove" onClick="javascript:remove();">卸载</button>
        <button id="run" onClick="javascript:try {aa()} catch (e){alert(e)};">alert1</button>
    </body>
</html>